from impl.common import DownloaderState
from impl.baidu import download_image_search_result_from_baidu


def download_worker_entry(search_identity: str, search_name: str, workspace_dir: str, db_config: dict, target_number: int,
                          proxy_address: str, headless: bool, enable_io_perf_stat: bool, enable_rich_log: bool,
                          new_requests_launch_interval: float, retry_times_on_empty_response: int,
                          shared_value):
    state, count = download_image_search_result_from_baidu(
        search_identity, search_name, workspace_dir, db_config, target_number, proxy_address, headless,
        enable_io_perf_stat, enable_rich_log, new_requests_launch_interval, retry_times_on_empty_response)
    if state == DownloaderState.Skipped:
        count = -1
    elif state == DownloaderState.Fail:
        count = 0
    shared_value.value = count
